#include "type.h"
#include "pxe.h"
#include "io.h"
#include "mem.h"
#include "msg.h"
#include "pxe_api.h"
#include "fbm.h"
#include "draw.h"

static void show_welcome()
{
	puts(MSG_WELCOME);
}

static int check_pxe(struct pxe far *fp_pxe)
{
	if (fp_pxe == NULL)
		return 1;

	if (memcmp(fp_pxe->Signature, "!PXE", 4))
		return 1;

	if (checksum((uint8 far *)fp_pxe, fp_pxe->StructLength))
		return 1;

	return 0;
}

static int check_pxenv(struct pxenv far *fp_pxenv)
{
	if (fp_pxenv == NULL)
		return 1;

	if (memcmp(fp_pxenv->Signature, "PXENV+", 6))
		return 1;

	if (checksum((uint8 far *)fp_pxenv, fp_pxenv->StructLength))
		return 1;

	return 0;
}

static int check_environment(struct pxe far *fp_pxe, struct pxenv far *fp_pxenv)
{
	uint32	value = 0;

	if (check_pxe(fp_pxe))
		return 1;

	if (check_pxenv(fp_pxenv))
		return 1;

	value = (uint32)get_fbm();
	value *= 1024;

	set_text_color(4);
	puts(MSG_FBM);
	putl(value, 10);
	return 0;
}

uint16 nbp_entry(struct pxe far *fp_pxe, struct pxenv far *fp_pxenv)
{
	set_mode(MODE_DRAW);
	show_welcome();
	if (check_environment(fp_pxe, fp_pxenv)) {
		return 0;
	} else {
	}

	return 0;
}
